# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=hoper
pkgver=v0.1.1.r0.g8d5dbd9
pkgrel=1
epoch=1
pkgdesc="Trace URL's jumps across the rel links to obtain the last URL."
groups=('blackarch' 'blackarch-recon')
arch=('any')
url='https://github.com/gabamnml/hoper'
license=('MIT')
depends=('ruby' 'ruby-bundler' 'libxslt')
makedepends=('git')
source=("git+https://github.com/gabamnml/$pkgname.git")
install="$pkgname.install"
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i 's|#!/usr/bin/env ruby -wU|#!/usr/bin/env ruby|g' "exe/$pkgname"

  sed -i 's|"bundler", "~> 1.12"|"bundler"|g' "$pkgname.gemspec"
  sed -i 's|"rake", "~> 1.10.0"|"bundler"|g' "$pkgname.gemspec"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
  install -Dm 644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md LICENSE.txt

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec bundle exec ./exe/$pkgname "\$@"
EOF

  chmod a+x "$pkgdir/usr/bin/$pkgname"
}

